/**
 * Created by admin on 2017/10/30.
 */

//百度地图搜索
function searchByStationName() {
    map.clearOverlays();//清空原来的标注
    var keyword = document.getElementById("text_").value;
    var localSearch = new BMap.LocalSearch(map);
    localSearch.enableAutoViewport(); //允许自动调节窗体大小

    localSearch.setSearchCompleteCallback(function (searchResult) {
        var poi = searchResult.getPoi(0);
        document.getElementById("long").value = poi.point.lng ;
        document.getElementById("lat").value = poi.point.lat;
        map.centerAndZoom(poi.point, 13);
        var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
        map.addOverlay(marker);
        marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
        // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    });
    localSearch.search(keyword);
}

//加载百度地图默认配置
function get_baidu(long = 104.072605,lat = 30.662945,width= 0,height =0) {
    if(long == '' || isNaN(long) ||  isNaN(lat) || lat == ''){
        long = 104.072605;
        lat = 30.662945;
    }
    var point = new BMap.Point(long,lat);
    //设置地图中心坐标
    map.centerAndZoom(point,12);
    //设置地图偏移
    map.panBy(width, height);
    //标注已有的坐标
    var marker = new BMap.Marker(new BMap.Point(long, lat));
    map.addOverlay(marker);

    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
    //    map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开

    //单击获取点击的经纬度
    map.addEventListener("click",function(e){
        document.getElementById("long").value = e.point.lng ;
        document.getElementById("lat").value = e.point.lat;
        map.clearOverlays();//清空原来的标注
        var marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat));
        map.addOverlay(marker);
    });
}

//单选，复选按钮
function checks () {
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green'
    })
}

